<?php


namespace app\crm\controller;

use app\admin\controller\ApiCommon;
use app\crm\model\OrderStatistics as OrderStatisticsModel;
use app\crm\model\CustomerPhoto as CustomerPhotoModel;
use app\shop\model\Warehouse;
use app\shop\model\Warehouse as WarehouseModel;
use think\facade\Db;
use think\response\Json;

/**
 * 订单相关统计
 * Class LeadsCommunal
 * @package app\crm\controller
 * @author Mr.Li
 * @create 2021-08-16 14:13
 */
class OrderStatistics extends ApiCommon
{

    /**
     * @author Mr.Liu
     * @create 2021-11-25 14:13
     */
    public function initialize()
    {
        $action = [
            'permission'=>[''],
            'allow'=>['']
        ];
        event('CheckAuth', $action);
        $request = $this->request;
        $a       = strtolower($request->action());
        if (!in_array($a, $action['permission'])) {
            parent::initialize();
        }
    }



    /**
     * 优惠明细
     * @auth true
     * @return Json
     * @author Mr.Liu
     * @update 2021-11-25 10:09
     */
    public function DiscountDetails():Json
    {
        $OrderStatisticsModel = new OrderStatisticsModel();
        $this->param['shopIds'] = $this->getCommonShopIdsCollectByUserType();
        $data   = $OrderStatisticsModel->getDataList($this->param);
        if (!$data) {
            return resultArray(['error' => $OrderStatisticsModel->getError()]);
        }
        return resultArray(['error'=>'获取成功','data' => $data]);
    }



    /**
     * 财务报表（销售日报表）
     * @auth true
     * @return Json
     * @author Mr.Liu
     * @update 2021-11-30 10:09
     */
    public function DayDetails():Json
    {
        $OrderStatisticsModel = new OrderStatisticsModel();
        $this->param['shopIds'] = $this->getCommonShopIdsCollectByUserType();
        $data   = $OrderStatisticsModel->getDayList($this->param);
        if (!$data) {
            return resultArray(['error' => $OrderStatisticsModel->getError()]);
        }
        return resultArray(['error'=>'获取成功','data' => $data]);
    }

    /**
     * 进店成交明细表
     * @auth true
     * @return Json
     * @author Mr.Liu
     * @update 2021-11-30 15:25
     */
    public function OrderDetails():Json
    {
        $OrderStatisticsModel = new OrderStatisticsModel();
        $this->param['shopIds'] = $this->getCommonShopIdsCollectByUserType();
        $data   = $OrderStatisticsModel->getOrderList($this->param);
        if (!$data) {
            return resultArray(['error' => $OrderStatisticsModel->getError()]);
        }
        return resultArray(['error'=>'获取成功','data' => $data]);
    }

    /**
     * 进店保有率明细
     * @auth true
     * @return Json
     * @author Mr.Liu
     * @update 2021-11-30 15:25
     */
    public function EnterDetails():Json
    {
        $OrderStatisticsModel = new OrderStatisticsModel();
        $data   = $OrderStatisticsModel->getEnterOrderDetail($this->param);
        if (!$data) {
            return resultArray(['error' => $OrderStatisticsModel->getError()]);
        }
        return resultArray(['error'=>'获取成功','data' => $data]);
    }


    /**
     * 成交保有率明细
     * @auth true
     * @return Json
     * @author Mr.Liu
     * @update 2021-11-30 15:25
     */
    public function DealDetails():Json
    {
        $OrderStatisticsModel = new OrderStatisticsModel();
        $data   = $OrderStatisticsModel->getDealDetails($this->param);
        if (!$data) {
            return resultArray(['error' => $OrderStatisticsModel->getError()]);
        }
        return resultArray(['error'=>'获取成功','data' => $data]);
    }









}
